﻿<?php

class ProtModel extends BaseModel
{

    var $table  = 'product';	

    var $_page_rows = 20;	
	
    /* 插入数据 */
    function insert_id()
    {    
	
	     $this->IU_Sql_Exe(array ('data' => array('name'=>"",'display'=>"0"), 'mode' => 'INSERT'));
		 
		 return $this->db->insert_id();	 
        
    }

    /* 插入数据 */
    function select_id()
    {    
		 $info = $this->S_Sql_Exe(array('fields' =>'id','conditions' =>"name = '' "));
    
		 return $info;
        
    }


    function delet_id()
    {    
		return $this->D_Sql_Exe(array ('conditions' =>"name = '' "));
       
    }

	
    /* 插入数据 */
    function post($id,$data)
    {    
	
		$time = time();  
		
		$this->IU_Sql_Exe(array ('data' => array('cat_id'=>"$data[cat_id]",'groupid'=>"$data[groupid]",'sellerid'=>"$data[sellerid]",'name'=>"$data[name]",'price'=>"$data[price]",'nowprice'=>"$data[nowprice]",'bookprice'=>"$data[bookprice]",'img'=>"$data[img]",'content'=>"$data[content]",'display'=>"$data[display]",'addtime'=>"$time"),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));   
    
   		
    }

    function show($order='',$v='',$word='')
    {  
	     empty($order)?$order = 'addtime desc':'';
		 
   	    $conditions = " name !='' ";
		 
		 foreach($word as $key => $value)
		 {

		     if($value)
		     {
		      $conditions .= " and name like '%{$value}%' ";
	  
		     }
		 }	
		  
	  

	  
	      //分页时，一定是先调用page函数，再调用S_Sql_Exe函数
		 $info['page'] = $this->Page(array('conditions' =>"{$conditions}",'url' => 'admin/?app=prot&act=index&v='.$v));		
		 
		 $info['data'] = $this->S_Sql_Exe(array('fields'=> ' * ','conditions' =>"{$conditions}",'order' =>"{$order}",'limit' =>$info['page']['sql_limit']));
    
		 return $info;
   
    }
	
	
    /* 删除数据 */
    function del($id ='')
    {      
		$this->D_Sql_Exe(array ('conditions' =>"id = '{$id}' "));
        
    }

    /* 修改数据 */
    function editaction($id ='',$data = '')
    {    
		$time = time();  	      

		$this->IU_Sql_Exe(array ('data' => array('cat_id'=>"$data[cat_id]",'groupid'=>"$data[groupid]",'sellerid'=>"$data[sellerid]",'name'=>"$data[name]",'price'=>"$data[price]",'nowprice'=>"$data[nowprice]",'bookprice'=>"$data[bookprice]",'img'=>"$data[img]",'content'=>"$data[content]",'display'=>"$data[display]",'addtime'=>"$time"),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));  
    

        
    }

    /* 修改数据 */
    function editpicurl($id ='',$data = '')
    {   
     
		return $this->IU_Sql_Exe(array ('data' => array('img'=>"$data[picurl]"),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));
        
    }




    /* 修改数据 */
    function editstatus($id ='',$data = '')
    {   
     
		return $this->IU_Sql_Exe(array ('data' => array('status'=>"$data[status]"),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));
        
    }



    /* 通过id取出一条数据 */
    function oneshow($id ='')
    {    
	    
		 $info = $this->S_Sql_Exe(array('fields'=> ' * ','conditions' =>"id='{$id}' ",'return' =>'one'));
    
		 return $info;
        
    }


}




?>